package com.mtbu.servlet.sys;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mtbu.comm.Constant;


public class SysListener extends HttpServlet implements ServletContextListener {
    /**
	 * 
	 */
	private static final long serialVersionUID = -8071670162381385821L;
	private static final Logger logger = LoggerFactory.getLogger(SysListener.class);

    public void contextInitialized(ServletContextEvent sce) {

    	System.out.println("mypath:" + this.getClass().getClassLoader().getResource(""));
        //设置应用的物理路径
        String rootpath = sce.getServletContext().getRealPath("/");
        if(rootpath != null) {
            rootpath = rootpath.replaceAll("\\\\", "/");
        } else {
            rootpath = "/";
        }
        if(!rootpath.endsWith("/")) {
            rootpath = rootpath + "/";
        }
        //rootpath = SuperString.replace(rootpath, "/", File.separator);
        Constant.ROOTPATH = rootpath;
        logger.info("===============================================");
        logger.info("Application Run Path:" + Constant.ROOTPATH);
        logger.info("===============================================");

        Constant.init();

    }

    public void contextDestroyed(ServletContextEvent arg0) {
        //PropUtil.releasePropReloader();
    }
}